/*-\|/-\|/-\|/-\|/
Support File of 
PCB functions for R2 

Version 1.0
|/-\|/-\|/-\|/-\*/
#include <stdio.h>
#include "mrj_supt.h"
//#include "mpx_supt.h"

int setPCB(char* name, int priority, int Pclass){
	//Allocate memory for PCB
	pcb *newPCB;
	newPCB = allocPCB();
	//Compare name string using findPCB function to check if name is unique
	if(find_PCB(name)!=NULL){
		printf("ERROR: Process already exists");
		return 0;
	}
	else
		strcpy(newPCB->name, name);
	
	//Check to see if priority is valid; between -128 and 127
	if((priority < -128) || (priority > 127)){
		printf("ERROR: Process priority is invalid, please enter a value"
		       "between -128 and 127");
		return 0;
	}
	else
		newPCB->priority = priority;
	//Check to see if the PCB Class is valid
	if((Pclass != PCB_CLASS_SYSTEM) || (Pclass != PCB_CLASS_APP)){
		printf("ERROR: Process class is invalid, please enter a correct value:"
		       "0 for System Process, 1 for Application Process");
		return 0;
	}
	else
		newPCB->Pclass = Pclass;
	//Set up initial states
	newPCB->state = PCB_STATE_RUN;
	newPCB->susp = PCB_FLAG_FREE;
	newPCB->memSize = 0;
	newPCB->stackT = NULL;
	newPCB->stackB = NULL;
	newPCB->locAddr = NULL;
	newPCB->excAddr = NULL;
	return 1;
}

pcb* allocPCB(){
	pcb *temPCB;
	temPCB = (sys_alloc_mem(PCB_STACK_SIZE));
	return temPCB;
}


